use std::fs::File;

#[derive(Debug)]
pub struct InputParams<'a> {
    pub file_path_1: &'a String,
    pub file_path_2: &'a String
}

pub fn input_from_args(args: &Vec<String>) -> Result<InputParams, String> {
    let file_path1 = args.get(1).ok_or("missing path to first file".to_string());
    let file_path2 = args.get(2).ok_or("missing path to second file".to_string());

    file_path1.and_then(|f1| 
        file_path2.map(|f2| 
            InputParams {
                file_path_1: f1,
                file_path_2: f2
            }
        )
    )
}

pub fn open_files(in_args: &InputParams) -> Result<(File, File), String> {
    let f1 = File::open(in_args.file_path_1).map_err(|e| e.to_string())?;
    let f2 = File::open(in_args.file_path_2).map_err(|e| e.to_string())?;
    Result::Ok((f1, f2))
}
